############################################
############################################
## This Makefile is in charge of building  ##
## and running all tests together.        ##
############################################
############################################
#
# Include dirs
INC = -I /usr/include/CUnit/ -I ../../Src/Include/ -I ../MkdirTest -I ../FormatTest -I ../OpenTest -I ../RW_Test
# Compiler
CC = gcc
# Compiler flags
CFLAGS = -Wall -pedantic -g
# Where the libfat lib lives
LIB_PATH = -L ../../lib/
# Directory containing format test suite
FORMAT_DIR = ../FormatTest/
# Directory containing format test suite
MKDIR_DIR = ../MkdirTest/
# Direcotry containing open test suite
OPEN_DIR = ../OpenTest
# Direcotry containing Read/Write  test suite
RW_DIR = ../RW_Test
# Where test binary lives
OBJ = ../FormatTest/format_suite.o ../MkdirTest/mkdir_suite.o ../OpenTest/open_suite.o ../RW_Test/rw_suite.o

.PHONY: test clean test_format test_mkdir test_open test_rw

all_tests: ../../bin/libfat.a $(OBJ)  all_tests.o 
	$(CC)  $(LIB_PATH) -o all_tests $^  -lcunit -lfat 

all_tests.o:  all_tests.c
	$(CC) $(CFLAGS) $(INC) -c $<



# Target for running all tests. 
test: test_format  test_mkdir test_open test_rw all_tests
	./all_tests
	@echo -e "\n\n\a *** Test complessivo superato! ***\n"	

# Target for building formatting test suite
test_format:
	$(MAKE) --directory=$(FORMAT_DIR) clean
	$(MAKE) --directory=$(FORMAT_DIR)

# Target for building mkdir test suite
test_mkdir:
	$(MAKE) --directory=$(MKDIR_DIR) clean
	$(MAKE) --directory=$(MKDIR_DIR)

# Target for building open test suite
test_open:
	$(MAKE) --directory=$(OPEN_DIR) clean
	$(MAKE) --directory=$(OPEN_DIR)

# Target for building R/W test suite
test_rw:
	$(MAKE) --directory=$(RW_DIR) clean
	$(MAKE) --directory=$(RW_DIR)

clean:
	rm -f *.o
	rm -f all_tests
	rm -f *~
